import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login/Login'
import AdminsSystem from "../views/system/AdminsSystem"
import apis from "../http/apis/apis"

Vue.use(VueRouter)

const routes = [
    {
        path:'/',
        redirect:'/login'
    },
    //超级管理员登录
    {
        path: '/superAdminsLogin',
        name: 'SuperAdminsLogin',
        component: () => import('../components/superAdmins/Login')
    },
    //普通管理员登录
    {
        path: '/adminsLogin',
        name: 'AdminsLogin',
        component: () => import('../components/admins/Login')
    },
    {
        path: '/login',
        name: 'Login',
        component: Login
    },
    {
        path: '/register',
        name: 'Register',
        component: () => import("../views/register/Register.vue")
    },
    //普通管理员
    {
        path: '/adminsSystem',
        name: 'adminsSystem',
        beforeEnter: async (to, from, next) => {
            const data = await apis.lessors.isLogin(localStorage.token)
            if (data.data.type == 401) {
                alert("请登录")
                next("/adminsLogin")
            } else {
                next()
            }
        },
        component: AdminsSystem,
        children: [
            {
                path: 'orders',
                name: 'orders',
                component: () => import('./../components/orders/orders.vue'),
                children: [
                    {
                        path: 'ordersList',
                        component: () => import('./../components/orders/ordersList.vue')
                    }
                ]
            },
            //投诉
            {
                path: 'adminsComplaints',
                component: () => import('../components/admins/AdminsComplaints')
            },
            {
                path:'adminsCompaints/:_id',
                component:()=>import('../components/admins/HandleComplaints'),
                props:true
            },
            //管理租客信息
            {
                path: 'adminsTenantsInformation',
                component: () => import('../components/admins/AdminsTenantsInformation')
            },
            //管理出租信息
            {
                path: 'adminsLessorsInformation',
                component: () => import('../components/admins/AdminsLessorsInformation')
            },
            //管理车位信息
            {
                path: 'adminsParkings',
                component: () => import('../components/admins/AdminsParkings')
            },
        ]
    },

    //超级管理员
    {
        path: '/superAdminsSystem',
        name: 'superAdminsSystem',
        beforeEnter:async (to,from,next)=>{
            const data = await apis.adminsApi.isLogin(localStorage.token)
            if(data.data.type==401){
                alert("请登录")
                next("/superAdminsLogin")
            }else{
                next()
            }
        },
        component: () => import('../views/system/SuperAdminsSystem'),
        children: [
            //新增管理员
            {
                path: 'addAdmins',
                name: 'AddAdmins',
                component: () => import('../components/superAdmins/AddAdmins')
            },
            //管理员修改禁用
            {
                path: 'listAdmins',
                name: 'ListAdmins',
                component: () => import('../components/superAdmins/ListAdmins')
            },
            //管理员登录日志
            {
                path: 'logAdmins',
                name: 'LogAdmins',
                component: () => import('../components/superAdmins/LogAdmins')
            },
            {
                path:'showData',
                name:'ShowData',
                component:()=>import('../components/superAdmins/ShowData')
            },
        ]
    },
    {
        path: '/lessors',
        name: 'Lessors',
        beforeEnter: async (to, from, next) => {
            const data = await apis.lessors.isLogin(localStorage.token)
            if (data.data.type == 401) {
                alert("请登录")
                next("/login")
            } else {
                next()
            }
        },
        component: () => import('../views/system/LessorsSystem'),
        children: [
            {
                path: "addParkings",
                name: 'AddParkings',
                component: () => import('../components/lessors/AddParkings')
            },
            {
                path: 'onShelf',
                name: 'OnShelf',
                component: () => import('../components/lessors/OnShelf')
            },
            {
                path: 'offShelf',
                name: 'OffShelf',
                component: () => import('../components/lessors/OffShelf')
            },
            {
                path: "searchlessors",
                component: () => import('../components/lessors/searchLessorsNav.vue'),
            },
            {
                path: 'lessorsSystemOrders',
                name: "LessorsSystemOrders",
                props: true,
                component: () => import('../components/lessors/LessorsSystemOrders')
            },
            {
                path: 'lessorsSystemOrders/:_id',
                name: 'OrdersDetails',
                props: true,
                component: () => import("../components/lessors/OrdersDetails")
            },
            {
                path: "searchlessors",
                component: () => import('../components/lessors/searchLessorsNav.vue'),
            },
            {
                path: "updataLessors/:_id",
                props:true,
                component: () => import('../components/lessors/updataLessors.vue'),
            },
        ]
    },


]

const router = new VueRouter({
    routes
})

export default router
